import * as fs from 'fs'

/**
 * 读取json文件
 * @param filePath 文件路径
 * @returns json对象
 */
export const readJson = (filePath: string) => { 
    return JSON.parse(fs.readFileSync(filePath, 'utf-8'))
}

/**
 * 写入json文件
 * @param filePath 文件路径
 * @param data json对象
 */
export const writeJson = (filePath: string, data: any) => {
    let writeData = data
    if (typeof data !== 'string') {
        writeData = JSON.stringify(data, null, 4)
    }
    fs.writeFileSync(filePath, writeData, 'utf-8')
}
